# 使用Yum安装一个命令名称与软件包名一样的软件包
function InstallCommandIfNotInstalled() {
  local command="${1}"
  if ! command -v "${command}" &> /dev/null; then
    yum -y -q install "${command}"
  fi
}

# 启动内容服务
function InstallHttpSeriveIfNotInstalled() {
  export listenHost="$1"
  export listenPort="$2"
  export dataRoot="$3"
  local dataPath="$4"
  local srcFile="$5"
  local dstFile="$6"

  yum -y localinstall "${dataPath}/nginx-*.rpm" &> /dev/null
  envsubst < "${src_file}" > "${dst_file}"

  export -n listenHost
  export -n listenPort
  export -n dataRoot
}

# 检查docker是否被安装，如果没安装则安装
function InstallDockerIfNotInstalled() {

  [ -f "/usr/bin/dockerd" ] && return 0

  local centos_version=$(cat /etc/centos-release | awk '{print $4}' )
  if [[ "${centos_version}" == "7.4.1708" ]];then
    yum -y -q install container-selinux-2.36 || yum -y -q install container-selinux
    yum -y -q install docker-ce-18.06.3.ce
  elif [[ "${centos_version}" == "7.5.1804" ]]; then
    yum -y -q install container-selinux-2.66 || yum -y -q install container-selinux
    yum -y -q install docker-ce-18.06.3.ce
  elif  [[ "${centos_version}" == "7.6.1810" ]]; then
    yum -y -q install container-selinux-2.74 || yum -y -q install container-selinux
    yum -y -q install docker-ce-18.09.9
  fi
}